package com.wmapp.domain;

import com.wmapp.utils.Pserver;
import com.wmapp.utils.SimpleStringUtils;

/**
 * Actually conference participant domain
 * 
 * @author dengl
 * 
 */
public class ConfParticipant {
	private String p_callId;
	private String p_audioMute;	// boolean MCU静音
	private String p_micMute;	// boolean 终端静音
	private String p_connectTime;
	private String p_audioRxCodec;
	private String p_audioTxCodec;
	private String p_videoRxCodec;
	private String p_videoTxCodec;
	
	private String p_number;
	private String p_name;
	private String p_ip;
	private String p_bandwidth;
	private String p_autoInvite;
	private String p_nameOverrideStatus="true"; //this field value always "true"
	private String p_nameOverrideValue;
	private String p_videoEnabled;
	private String p_email;
	private String p_connected;
	private String p_dir;
    private String p_utility;
	
	private String status;
	private String audio;
	private String micmute;
	//private String video;
	private String preview;
	
	private boolean isLecture;//whether is lecture
	private boolean isH239Owner;
	private boolean isChairperson;
	private String confNumber;

	private String link;
	private String bandwidth;
	private String p_networkstatus;	// 网络状况: good,bad,medium
	private String dir;
	
	//These fields belong invited participants
	public static final String[] ADD_PARAM_FIELDS_FOR_INVITE={"p_number","p_name","p_ip","p_bandwidth","p_autoInvite","p_nameOverrideStatus","p_nameOverrideValue","p_videoEnabled","p_email"};
	
	public static final String[] ADD_PARAM_FIELDS_FOR_RESERVATION={"p_number","p_name","p_ip","p_bandwidth","p_autoInvite","p_nameOverrideStatus","p_nameOverrideValue","p_videoEnabled"};
	public static final String[] ADD_PARAM_NODES_FOR_RESERVATION={"number","name","ip","bandwidth","autoInvite","nameOverrideStatus","nameOverrideValue","videoEnabled"};
	
	public static final String[] UPDATE_PARAM_FIELDS_FOR_RESERVATION={"p_number","p_name","p_ip","p_bandwidth","p_autoInvite","p_nameOverrideStatus","p_nameOverrideValue","p_videoEnabled"};
	public static final String[] UPDATE_PARAM_NODES_FOR_RESERVATION={"number","name","ip","bandwidth","autoInvite","nameOverrideStatus","nameOverrideValue","videoEnabled"};
	
	public static final String[] MODIFY_PARAM_FIELDS_FOR_INVITE={"p_number","p_name","p_ip","p_bandwidth","p_autoInvite","p_nameOverrideStatus","p_nameOverrideValue","p_videoEnabled","p_email"};
	
	public static final String[] INVITE_PARAM_FIELDS={"p_number","p_ip","p_bandwidth","p_videoEnabled"};
	
	public static final String[] FIELDS_FOR_CONF_RESERVATION={"p_number","p_nameOverrideValue","p_autoInvite","p_ip","p_bandwidth","p_videoEnabled"};
	
	//public static final String[] GRID_FIELDS_FOR_PRESENT = { "p_number","p_nameOverrideValue", "status", "audio","video","p_bandwidth","preview"};
	public static final String[] GRID_FIELDS_FOR_PRESENT = { "link","p_number","p_nameOverrideValue", "status", "audio","micmute","bandwidth","dir","preview","p_connected"};
   
	
	public String getLink() {
		StringBuffer ret=new StringBuffer();
		if(this.p_connected == null || this.p_connected.equals("false")){
			ret.append(SimpleStringUtils.join("<span ><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/link_break.png></span>"));
		}else{
			ret.append(SimpleStringUtils.join("<span ><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/link.png></span>"));
		}
		return ret.toString();
	}
    public String getP_utility() {
		return p_utility;
	}

	public void setP_utility(String p_utility) {
		this.p_utility = p_utility;
	}


	public String getP_connected() {
		return p_connected;
	}

	public void setP_connected(String p_connected) {
		this.p_connected = p_connected;
	}

	public String getDir() {
		StringBuffer ret=new StringBuffer();
		if(this.p_dir == null ){

		}else {
			ret.append("<div>");
			if(this.p_dir.equals("Call Out")){
				ret.append(SimpleStringUtils.join("<span title=$img.tip.callout><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/callout.png></span>"));
			}else{
				ret.append(SimpleStringUtils.join("<span title=$img.tip.callin><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/callin.png></span>"));
			}
			ret.append("</div>");
		}
		return ret.toString();
	}

	public String getP_dir() {
		return p_dir;
	}

	public void setP_dir(String dir) {
		this.p_dir = dir;
	}

	public String getP_number() {
		return p_number;
	}

	public void setP_number(String p_number) {
		this.p_number = p_number;
	}

	public String getP_name() {
		return p_name;
	}

	public void setP_name(String p_name) {
		this.p_name = p_name;
	}

	public String getP_ip() {
		return p_ip;
	}

	public void setP_ip(String p_ip) {
		this.p_ip = p_ip;
	}

	public String getBandwidth() {
		StringBuffer ret=new StringBuffer();
		ret.append("<div>");
		if(this.p_connected == null || this.p_connected.equals("false")){
			ret.append(SimpleStringUtils.join("<span  title=$img.tip.network.offline><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/network-status-offline.png></span>"));
		}else if(this.p_networkstatus == null || this.p_networkstatus.equals("good")){
			ret.append(SimpleStringUtils.join("<span  title=$img.tip.network.good><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/network-status-good.png></span>"));
		}else if( this.p_networkstatus.equals("bad")){
			ret.append(SimpleStringUtils.join("<span title=$img.tip.network.bad><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/network-status-busy.png></span>"));
		}else{
			ret.append(SimpleStringUtils.join("<span title=$img.tip.network.medium><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/network-status-medium.png></span>"));
		}

		ret.append(p_bandwidth);
		ret.append("</div>");
		return ret.toString();
	}

	public String getP_bandwidth() {
		return p_bandwidth;
	}

	public void setP_bandwidth(String p_bandwidth) {
		this.p_bandwidth = p_bandwidth;
	}

	public String getP_networkstatus() {
		return p_networkstatus;
	}

	public void setP_networkstatus(String status) {
		this.p_networkstatus = status;
	}

	public String getP_autoInvite() {
		return p_autoInvite;
	}

	public void setP_autoInvite(String p_autoInvite) {
		this.p_autoInvite = p_autoInvite;
	}

	public String getP_nameOverrideStatus() {
		return p_nameOverrideStatus;
	}

	public void setP_nameOverrideStatus(String p_nameOverrideStatus) {
		this.p_nameOverrideStatus = "true";
	}

	public String getP_nameOverrideValue() {
		return p_nameOverrideValue;
	}

	public void setP_nameOverrideValue(String p_nameOverrideValue) {
		this.p_nameOverrideValue = p_nameOverrideValue;
	}

	public String getP_videoEnabled() {
		return p_videoEnabled;
	}

	public void setP_videoEnabled(String p_videoEnabled) {
		this.p_videoEnabled = p_videoEnabled;
	}

	public String getP_email() {
		return p_email;
	}

	public void setP_email(String p_email) {
		this.p_email = p_email;
	}

	public String getP_callId() {
		return p_callId;
	}

	public void setP_callId(String p_callId) {
		this.p_callId = p_callId;
	}

	public String getP_audioMute() {
		return p_audioMute;
	}

	public void setP_audioMute(String p_audioMute) {
		this.p_audioMute = p_audioMute;
	}

	public String getP_micMute() {
		return p_micMute;
	}

	public void setP_micMute(String p_micMute) {
		this.p_micMute = p_micMute;
	}

	public String getP_connectTime() {
		return p_connectTime;
	}

	public void setP_connectTime(String p_connectTime) {
		this.p_connectTime = p_connectTime;
	}

	public String getP_audioRxCodec() {
		return p_audioRxCodec;
	}

	public void setP_audioRxCodec(String p_audioRxCodec) {
		this.p_audioRxCodec = p_audioRxCodec;
	}

	public String getP_audioTxCodec() {
		return p_audioTxCodec;
	}

	public void setP_audioTxCodec(String p_audioTxCodec) {
		this.p_audioTxCodec = p_audioTxCodec;
	}

	public String getP_videoRxCodec() {
		return p_videoRxCodec;
	}

	public void setP_videoRxCodec(String p_videoRxCodec) {
		this.p_videoRxCodec = p_videoRxCodec;
	}

	public String getP_videoTxCodec() {
		return p_videoTxCodec;
	}

	public void setP_videoTxCodec(String p_videoTxCodec) {
		this.p_videoTxCodec = p_videoTxCodec;
	}

	public String getStatus() {
		StringBuffer ret=new StringBuffer();
		if (this.p_connected == null || this.p_connected.equals("false")) {
		}
		else {       
		if(this.isLecture)
			ret.append(SimpleStringUtils.join("<span title=$img.tip.lecture><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/lecture.png></span>"));		
		if(this.isH239Owner)
			ret.append(SimpleStringUtils.join("<span title=$img.tip.h239owner><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/chart.png></span>"));
		if(this.isChairperson)
			ret.append(SimpleStringUtils.join("<span title=$img.tip.chairperson><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/privilege.png></span>"));
        if(this.p_utility.equals("true"))
            ret.append(SimpleStringUtils.join("<span title=$img.tip.record><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/record.png></span>"));
        }
		return ret.toString();
	}

	public String getAudio() {
		StringBuffer ret=new StringBuffer();
		/*ret.append(SimpleStringUtils.join("<div><label class=i18n>$conf.ctrl.rx</label>: ",this.p_audioRxCodec));
		if(this.p_micMute!=null&&this.p_micMute.equals("true")){
			ret.append(SimpleStringUtils.join("<span title=$img.tip.mute><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/unmute.png></span></div>"));
		}else{
			ret.append(SimpleStringUtils.join("<span title=$img.tip.speak><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/mute.png></span></div>"));
		}
		ret.append(SimpleStringUtils.join("<div><label class=i18n>$conf.ctrl.tx</label>: ",this.p_audioTxCodec,"</div>"));*/
		if (this.p_connected == null || this.p_connected.equals("false")) {
		}
		else {
			ret.append("<div>");
		if(this.p_audioMute!=null&&this.p_audioMute.equals("true")){
			ret.append(SimpleStringUtils.join("<span title=$img.tip.mute><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/unmute.png></span>"));
		}else{
			ret.append(SimpleStringUtils.join("<span title=$img.tip.speak><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/mute.png></span>"));
		}
			ret.append("</div>");
		}
		return ret.toString();
	}

	public String getMicmute() {
		StringBuffer ret=new StringBuffer();
		if (this.p_connected == null || this.p_connected.equals("false")) {
		}
		else {
			ret.append("<div>");
		if(this.p_micMute!=null&&this.p_micMute.equals("true")){
			ret.append(SimpleStringUtils.join("<span title=$img.tip.micomute><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/unmute.png></span></div>"));
		}else{
			ret.append(SimpleStringUtils.join("<span title=$img.tip.micspeak><img src=",Pserver.getInstance().getContextPath(),"/styles/default/images/mute.png></span></div>"));
		}
			ret.append("</div>");
		}
		return ret.toString();
	}
	/*
	public String getVideo() {
		StringBuffer ret=new StringBuffer();
		
		if(this.p_videoEnabled!=null&&!this.p_videoEnabled.equals("true")){
			ret.append(SimpleStringUtils.join("<div><span title=$img.tip.disable><img width=16 height=16 src=",Pserver.getInstance().getContextPath(),"/styles/default/images/audiocall.gif></span></div>"));
		}else{
			ret.append(SimpleStringUtils.join("<div><label class=i18n>$conf.ctrl.rx</label>: ",this.p_videoRxCodec,"</div>"));
			ret.append(SimpleStringUtils.join("<div><label class=i18n>$conf.ctrl.tx</label>: ",this.p_videoTxCodec,"</div>"));
		}
		
		return ret.toString();
	}*/

	public String getPreview() {
		StringBuffer ret = new StringBuffer();
		if(this.p_connected == null || this.p_connected.equals("false") ||
                (this.p_utility != null &&  this.p_utility.equals("true"))   ){
		
		}
		else
		{
			ret.append("<div>");
			if (this.p_videoEnabled != null && this.p_videoEnabled.equals("true") && this.p_callId != null) {
				String imgName = this.p_callId.replaceAll("conf/", "");
				ret.append(SimpleStringUtils.join("<img imgid=", imgName, " src=/snapshot/", imgName, ".jpg>", "</img>"));
			}

			if (isH239Owner) {
				ret.append(SimpleStringUtils.join("<img imgid=", confNumber, "_h239 src=/snapshot/", confNumber, "_h239.jpg>", "</img>"));
			}
			ret.append("</div>");
		}
		return ret.toString();
	}

	public boolean isLecture() {
		return isLecture;
	}

	public void setLecture(boolean isLecture) {
		this.isLecture = isLecture;
	}

	public boolean isH239Owner() {
		return isH239Owner;
	}

	public void setH239Owner(boolean isH239Owner) {
		this.isH239Owner = isH239Owner;
	}

	public boolean isChairperson() {
		return isChairperson;
	}

	public void setChairperson(boolean isChairperson) {
		this.isChairperson = isChairperson;
	}

	public void setConfNumber(String confNumber) {
		this.confNumber = confNumber;
	}
	
	
}
